<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  Foreign.C.String</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The FFI task force 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  ffi@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Utilities for primitive marshalling of C strings.</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- The marshalling converts each Haskell character, representing a Unicode</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- code point, to one or more bytes in a manner that, by default, is</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- determined by the current locale.  As a consequence, no guarantees</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- can be made about the relative length of a Haskell string and its</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- corresponding C string, and therefore all the marshalling routines</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- include memory allocation.  The translation between Unicode and the</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- encoding of the current locale may be lossy.</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Foreign.C.String</span><span> </span><span class="hs-special">(</span><span>   </span><span class="hs-comment">-- representation of strings in C</span><span>
</span><span id="line-27"></span><span>  </span><span class="annot"><span class="hs-comment">-- * C strings</span></span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier">CString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier">CStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Using a locale-dependent encoding</span></span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span>  </span><span class="hs-comment">-- | These functions are different from their @CAString@ counterparts</span><span>
</span><span id="line-35"></span><span>  </span><span class="hs-comment">-- in that they will use an encoding determined by the current locale,</span><span>
</span><span id="line-36"></span><span>  </span><span class="hs-comment">-- rather than always assuming ASCII.</span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span>  </span><span class="hs-comment">-- conversion of C strings into Haskell strings</span><span>
</span><span id="line-39"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCString"><span class="hs-identifier">peekCString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCStringLen"><span class="hs-identifier">peekCStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span>  </span><span class="hs-comment">-- conversion of Haskell strings into C strings</span><span>
</span><span id="line-44"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-45"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCString"><span class="hs-identifier">newCString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCStringLen"><span class="hs-identifier">newCStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span>  </span><span class="hs-comment">-- conversion of Haskell strings into C strings using temporary storage</span><span>
</span><span id="line-49"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-50"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCString"><span class="hs-identifier">withCString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-51"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCStringLen"><span class="hs-identifier">withCStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#charIsRepresentable"><span class="hs-identifier">charIsRepresentable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Using 8-bit characters</span></span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span>  </span><span class="hs-comment">-- | These variants of the above functions are for use with C libraries</span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-comment">-- that are ignorant of Unicode.  These functions should be used with</span><span>
</span><span id="line-59"></span><span>  </span><span class="hs-comment">-- care, as a loss of information can occur.</span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier">castCharToCChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-62"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCCharToChar"><span class="hs-identifier">castCCharToChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCharToCUChar"><span class="hs-identifier">castCharToCUChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-65"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCUCharToChar"><span class="hs-identifier">castCUCharToChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-66"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCharToCSChar"><span class="hs-identifier">castCharToCSChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-67"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#castCSCharToChar"><span class="hs-identifier">castCSCharToChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCAString"><span class="hs-identifier">peekCAString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-70"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCAStringLen"><span class="hs-identifier">peekCAStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-71"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCAString"><span class="hs-identifier">newCAString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-72"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCAStringLen"><span class="hs-identifier">newCAStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-73"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCAString"><span class="hs-identifier">withCAString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-74"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCAStringLen"><span class="hs-identifier">withCAStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-75"></span><span>
</span><span id="line-76"></span><span>  </span><span class="annot"><span class="hs-comment">-- * C wide strings</span></span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span>  </span><span class="hs-comment">-- | These variants of the above functions are for use with C libraries</span><span>
</span><span id="line-79"></span><span>  </span><span class="hs-comment">-- that encode Unicode using the C @wchar_t@ type in a system-dependent</span><span>
</span><span id="line-80"></span><span>  </span><span class="hs-comment">-- way.  The only encodings supported are</span><span>
</span><span id="line-81"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-82"></span><span>  </span><span class="hs-comment">-- * UTF-32 (the C compiler defines @__STDC_ISO_10646__@), or</span><span>
</span><span id="line-83"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-84"></span><span>  </span><span class="hs-comment">-- * UTF-16 (as used on Windows systems).</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier">CWString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-87"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#CWStringLen"><span class="hs-identifier">CWStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier">peekCWString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-90"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#peekCWStringLen"><span class="hs-identifier">peekCWStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-91"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCWString"><span class="hs-identifier">newCWString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-92"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#newCWStringLen"><span class="hs-identifier">newCWStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-93"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier">withCWString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-94"></span><span>  </span><span class="annot"><a href="Foreign.C.String.html#withCWStringLen"><span class="hs-identifier">withCWStringLen</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-97"></span><span>
</span><span id="line-98"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Array.html"><span class="hs-identifier">Foreign.Marshal.Array</span></a></span><span>
</span><span id="line-99"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>
</span><span id="line-100"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Ptr.html"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>
</span><span id="line-101"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Word.html"><span class="hs-identifier">Data.Word</span></a></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Char.html"><span class="hs-identifier">GHC.Char</span></a></span><span>
</span><span id="line-106"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>
</span><span id="line-107"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-108"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-109"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-110"></span><span>
</span><span id="line-111"></span><span class="hs-keyword">import</span><span> </span><span class="hs-pragma">{-# SOURCE</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html"><span class="hs-identifier">GHC.IO.Encoding</span></a></span><span>
</span><span id="line-112"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Foreign.html"><span class="hs-identifier">GHC.Foreign</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">GHC</span></span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-115"></span><span class="hs-comment">-- Strings</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span class="hs-comment">-- representation of strings in C</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- ------------------------------</span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="hs-comment">-- | A C string is a reference to an array of C characters terminated by NUL.</span><span>
</span><span id="line-121"></span><span class="hs-keyword">type</span><span> </span><span id="CString"><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-var">CString</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span>
</span><span id="line-122"></span><span>
</span><span id="line-123"></span><span class="hs-comment">-- | A string with explicit length information in bytes instead of a</span><span>
</span><span id="line-124"></span><span class="hs-comment">-- terminating NUL (allowing NUL characters in the middle of the string).</span><span>
</span><span id="line-125"></span><span class="hs-keyword">type</span><span> </span><span id="CStringLen"><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-var">CStringLen</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span class="hs-comment">-- exported functions</span><span>
</span><span id="line-128"></span><span class="hs-comment">-- ------------------</span><span>
</span><span id="line-129"></span><span class="hs-comment">--</span><span>
</span><span id="line-130"></span><span class="hs-comment">-- * the following routines apply the default conversion when converting the</span><span>
</span><span id="line-131"></span><span class="hs-comment">--   C-land character encoding into the Haskell-land character encoding</span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span class="hs-comment">-- | Marshal a NUL terminated C string into a Haskell string.</span><span>
</span><span id="line-134"></span><span class="hs-comment">--</span><span>
</span><span id="line-135"></span><span class="annot"><a href="Foreign.C.String.html#peekCString"><span class="hs-identifier hs-type">peekCString</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-136"></span><span id="peekCString"><span class="annot"><span class="annottext">peekCString :: CString -&gt; IO String
</span><a href="Foreign.C.String.html#peekCString"><span class="hs-identifier hs-var hs-var">peekCString</span></a></span></span><span> </span><span id="local-6989586621679530622"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530622"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; CString -&gt; IO String)
-&gt; CString -&gt; TextEncoding -&gt; IO String
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; CString -&gt; IO String
</span><a href="GHC.Foreign.html#peekCString"><span class="hs-identifier hs-var">GHC.peekCString</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530622"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-137"></span><span>
</span><span id="line-138"></span><span class="hs-comment">-- | Marshal a C string with explicit length into a Haskell string.</span><span>
</span><span id="line-139"></span><span class="hs-comment">--</span><span>
</span><span id="line-140"></span><span class="annot"><a href="Foreign.C.String.html#peekCStringLen"><span class="hs-identifier hs-type">peekCStringLen</span></a></span><span>           </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-141"></span><span id="peekCStringLen"><span class="annot"><span class="annottext">peekCStringLen :: CStringLen -&gt; IO String
</span><a href="Foreign.C.String.html#peekCStringLen"><span class="hs-identifier hs-var hs-var">peekCStringLen</span></a></span></span><span> </span><span id="local-6989586621679530618"><span class="annot"><span class="annottext">CStringLen
</span><a href="#local-6989586621679530618"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; CStringLen -&gt; IO String)
-&gt; CStringLen -&gt; TextEncoding -&gt; IO String
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; CStringLen -&gt; IO String
</span><a href="GHC.Foreign.html#peekCStringLen"><span class="hs-identifier hs-var">GHC.peekCStringLen</span></a></span><span> </span><span class="annot"><span class="annottext">CStringLen
</span><a href="#local-6989586621679530618"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C string.</span><span>
</span><span id="line-144"></span><span class="hs-comment">--</span><span>
</span><span id="line-145"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-146"></span><span class="hs-comment">--</span><span>
</span><span id="line-147"></span><span class="hs-comment">-- * new storage is allocated for the C string and must be</span><span>
</span><span id="line-148"></span><span class="hs-comment">--   explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-149"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-150"></span><span class="hs-comment">--</span><span>
</span><span id="line-151"></span><span class="annot"><a href="Foreign.C.String.html#newCString"><span class="hs-identifier hs-type">newCString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span>
</span><span id="line-152"></span><span id="newCString"><span class="annot"><span class="annottext">newCString :: String -&gt; IO CString
</span><a href="Foreign.C.String.html#newCString"><span class="hs-identifier hs-var hs-var">newCString</span></a></span></span><span> </span><span id="local-6989586621679530616"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530616"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO CString) -&gt; IO CString
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; String -&gt; IO CString)
-&gt; String -&gt; TextEncoding -&gt; IO CString
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; String -&gt; IO CString
</span><a href="GHC.Foreign.html#newCString"><span class="hs-identifier hs-var">GHC.newCString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530616"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | Marshal a Haskell string into a C string (ie, character array) with</span><span>
</span><span id="line-155"></span><span class="hs-comment">-- explicit length information.</span><span>
</span><span id="line-156"></span><span class="hs-comment">--</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- * new storage is allocated for the C string and must be</span><span>
</span><span id="line-158"></span><span class="hs-comment">--   explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-159"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-160"></span><span class="hs-comment">--</span><span>
</span><span id="line-161"></span><span class="annot"><a href="Foreign.C.String.html#newCStringLen"><span class="hs-identifier hs-type">newCStringLen</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span>
</span><span id="line-162"></span><span id="newCStringLen"><span class="annot"><span class="annottext">newCStringLen :: String -&gt; IO CStringLen
</span><a href="Foreign.C.String.html#newCStringLen"><span class="hs-identifier hs-var hs-var">newCStringLen</span></a></span></span><span> </span><span id="local-6989586621679530614"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530614"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO CStringLen) -&gt; IO CStringLen
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; String -&gt; IO CStringLen)
-&gt; String -&gt; TextEncoding -&gt; IO CStringLen
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; String -&gt; IO CStringLen
</span><a href="GHC.Foreign.html#newCStringLen"><span class="hs-identifier hs-var">GHC.newCStringLen</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530614"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C string using temporary</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- storage.</span><span>
</span><span id="line-166"></span><span class="hs-comment">--</span><span>
</span><span id="line-167"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-168"></span><span class="hs-comment">--</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-170"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-171"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-172"></span><span class="hs-comment">--</span><span>
</span><span id="line-173"></span><span id="local-6989586621679530780"><span class="annot"><a href="Foreign.C.String.html#withCString"><span class="hs-identifier hs-type">withCString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530780"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530780"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-174"></span><span id="withCString"><span class="annot"><span class="annottext">withCString :: forall a. String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCString"><span class="hs-identifier hs-var hs-var">withCString</span></a></span></span><span> </span><span id="local-6989586621679530611"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530611"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679530610"><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679530610"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO a) -&gt; IO a
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679530609"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679530609"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; String -&gt; (CString -&gt; IO a) -&gt; IO a
forall a. TextEncoding -&gt; String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="GHC.Foreign.html#withCString"><span class="hs-identifier hs-var">GHC.withCString</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679530609"><span class="hs-identifier hs-var">enc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530611"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679530610"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-175"></span><span>
</span><span id="line-176"></span><span class="hs-comment">-- | Marshal a Haskell string into a C string (ie, character array)</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- in temporary storage, with explicit length information.</span><span>
</span><span id="line-178"></span><span class="hs-comment">--</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-180"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-181"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-182"></span><span class="hs-comment">--</span><span>
</span><span id="line-183"></span><span id="local-6989586621679530777"><span class="annot"><a href="Foreign.C.String.html#withCStringLen"><span class="hs-identifier hs-type">withCStringLen</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530777"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530777"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-184"></span><span id="withCStringLen"><span class="annot"><span class="annottext">withCStringLen :: forall a. String -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCStringLen"><span class="hs-identifier hs-var hs-var">withCStringLen</span></a></span></span><span> </span><span id="local-6989586621679530606"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530606"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679530605"><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679530605"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO a) -&gt; IO a
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679530604"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679530604"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; String -&gt; (CStringLen -&gt; IO a) -&gt; IO a
forall a. TextEncoding -&gt; String -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="GHC.Foreign.html#withCStringLen"><span class="hs-identifier hs-var">GHC.withCStringLen</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679530604"><span class="hs-identifier hs-var">enc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530606"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679530605"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span class="hs-comment">-- -- | Determines whether a character can be accurately encoded in a 'CString'.</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- -- Unrepresentable characters are converted to '?' or their nearest visual equivalent.</span><span>
</span><span id="line-188"></span><span class="annot"><a href="Foreign.C.String.html#charIsRepresentable"><span class="hs-identifier hs-type">charIsRepresentable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-189"></span><span id="charIsRepresentable"><span class="annot"><span class="annottext">charIsRepresentable :: Char -&gt; IO Bool
</span><a href="Foreign.C.String.html#charIsRepresentable"><span class="hs-identifier hs-var hs-var">charIsRepresentable</span></a></span></span><span> </span><span id="local-6989586621679530602"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530602"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getForeignEncoding"><span class="hs-identifier hs-var">getForeignEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding -&gt; (TextEncoding -&gt; IO Bool) -&gt; IO Bool
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; Char -&gt; IO Bool)
-&gt; Char -&gt; TextEncoding -&gt; IO Bool
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; Char -&gt; IO Bool
</span><a href="GHC.Foreign.html#charIsRepresentable"><span class="hs-identifier hs-var">GHC.charIsRepresentable</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530602"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-190"></span><span>
</span><span id="line-191"></span><span class="hs-comment">-- single byte characters</span><span>
</span><span id="line-192"></span><span class="hs-comment">-- ----------------------</span><span>
</span><span id="line-193"></span><span class="hs-comment">--</span><span>
</span><span id="line-194"></span><span class="hs-comment">--   ** NOTE: These routines don't handle conversions! **</span><span>
</span><span id="line-195"></span><span>
</span><span id="line-196"></span><span class="hs-comment">-- | Convert a C byte, representing a Latin-1 character, to the corresponding</span><span>
</span><span id="line-197"></span><span class="hs-comment">-- Haskell character.</span><span>
</span><span id="line-198"></span><span class="annot"><a href="Foreign.C.String.html#castCCharToChar"><span class="hs-identifier hs-type">castCCharToChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-199"></span><span id="castCCharToChar"><span class="annot"><span class="annottext">castCCharToChar :: CChar -&gt; Char
</span><a href="Foreign.C.String.html#castCCharToChar"><span class="hs-identifier hs-var hs-var">castCCharToChar</span></a></span></span><span> </span><span id="local-6989586621679530600"><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530600"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Char
</span><a href="GHC.Base.html#unsafeChr"><span class="hs-identifier hs-var">unsafeChr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8 -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CChar -&gt; Word8
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530600"><span class="hs-identifier hs-var">ch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-200"></span><span>
</span><span id="line-201"></span><span class="hs-comment">-- | Convert a Haskell character to a C character.</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- This function is only safe on the first 256 characters.</span><span>
</span><span id="line-203"></span><span class="annot"><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-type">castCharToCChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span>
</span><span id="line-204"></span><span id="castCharToCChar"><span class="annot"><span class="annottext">castCharToCChar :: Char -&gt; CChar
</span><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-var hs-var">castCharToCChar</span></a></span></span><span> </span><span id="local-6989586621679530598"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530598"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CChar
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Int
</span><a href="GHC.Base.html#ord"><span class="hs-identifier hs-var">ord</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530598"><span class="hs-identifier hs-var">ch</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-205"></span><span>
</span><span id="line-206"></span><span class="hs-comment">-- | Convert a C @unsigned char@, representing a Latin-1 character, to</span><span>
</span><span id="line-207"></span><span class="hs-comment">-- the corresponding Haskell character.</span><span>
</span><span id="line-208"></span><span class="annot"><a href="Foreign.C.String.html#castCUCharToChar"><span class="hs-identifier hs-type">castCUCharToChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CUChar"><span class="hs-identifier hs-type">CUChar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-209"></span><span id="castCUCharToChar"><span class="annot"><span class="annottext">castCUCharToChar :: CUChar -&gt; Char
</span><a href="Foreign.C.String.html#castCUCharToChar"><span class="hs-identifier hs-var hs-var">castCUCharToChar</span></a></span></span><span> </span><span id="local-6989586621679530596"><span class="annot"><span class="annottext">CUChar
</span><a href="#local-6989586621679530596"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Char
</span><a href="GHC.Base.html#unsafeChr"><span class="hs-identifier hs-var">unsafeChr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8 -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CUChar -&gt; Word8
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CUChar
</span><a href="#local-6989586621679530596"><span class="hs-identifier hs-var">ch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-210"></span><span>
</span><span id="line-211"></span><span class="hs-comment">-- | Convert a Haskell character to a C @unsigned char@.</span><span>
</span><span id="line-212"></span><span class="hs-comment">-- This function is only safe on the first 256 characters.</span><span>
</span><span id="line-213"></span><span class="annot"><a href="Foreign.C.String.html#castCharToCUChar"><span class="hs-identifier hs-type">castCharToCUChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CUChar"><span class="hs-identifier hs-type">CUChar</span></a></span><span>
</span><span id="line-214"></span><span id="castCharToCUChar"><span class="annot"><span class="annottext">castCharToCUChar :: Char -&gt; CUChar
</span><a href="Foreign.C.String.html#castCharToCUChar"><span class="hs-identifier hs-var hs-var">castCharToCUChar</span></a></span></span><span> </span><span id="local-6989586621679530595"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530595"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CUChar
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Int
</span><a href="GHC.Base.html#ord"><span class="hs-identifier hs-var">ord</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530595"><span class="hs-identifier hs-var">ch</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-215"></span><span>
</span><span id="line-216"></span><span class="hs-comment">-- | Convert a C @signed char@, representing a Latin-1 character, to the</span><span>
</span><span id="line-217"></span><span class="hs-comment">-- corresponding Haskell character.</span><span>
</span><span id="line-218"></span><span class="annot"><a href="Foreign.C.String.html#castCSCharToChar"><span class="hs-identifier hs-type">castCSCharToChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSChar"><span class="hs-identifier hs-type">CSChar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-219"></span><span id="castCSCharToChar"><span class="annot"><span class="annottext">castCSCharToChar :: CSChar -&gt; Char
</span><a href="Foreign.C.String.html#castCSCharToChar"><span class="hs-identifier hs-var hs-var">castCSCharToChar</span></a></span></span><span> </span><span id="local-6989586621679530594"><span class="annot"><span class="annottext">CSChar
</span><a href="#local-6989586621679530594"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Char
</span><a href="GHC.Base.html#unsafeChr"><span class="hs-identifier hs-var">unsafeChr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8 -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CSChar -&gt; Word8
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CSChar
</span><a href="#local-6989586621679530594"><span class="hs-identifier hs-var">ch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-220"></span><span>
</span><span id="line-221"></span><span class="hs-comment">-- | Convert a Haskell character to a C @signed char@.</span><span>
</span><span id="line-222"></span><span class="hs-comment">-- This function is only safe on the first 256 characters.</span><span>
</span><span id="line-223"></span><span class="annot"><a href="Foreign.C.String.html#castCharToCSChar"><span class="hs-identifier hs-type">castCharToCSChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSChar"><span class="hs-identifier hs-type">CSChar</span></a></span><span>
</span><span id="line-224"></span><span id="castCharToCSChar"><span class="annot"><span class="annottext">castCharToCSChar :: Char -&gt; CSChar
</span><a href="Foreign.C.String.html#castCharToCSChar"><span class="hs-identifier hs-var hs-var">castCharToCSChar</span></a></span></span><span> </span><span id="local-6989586621679530593"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530593"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CSChar
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Int
</span><a href="GHC.Base.html#ord"><span class="hs-identifier hs-var">ord</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530593"><span class="hs-identifier hs-var">ch</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-225"></span><span>
</span><span id="line-226"></span><span class="hs-comment">-- | Marshal a NUL terminated C string into a Haskell string.</span><span>
</span><span id="line-227"></span><span class="hs-comment">--</span><span>
</span><span id="line-228"></span><span class="annot"><a href="Foreign.C.String.html#peekCAString"><span class="hs-identifier hs-type">peekCAString</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-229"></span><span id="peekCAString"><span class="annot"><span class="annottext">peekCAString :: CString -&gt; IO String
</span><a href="Foreign.C.String.html#peekCAString"><span class="hs-identifier hs-var hs-var">peekCAString</span></a></span></span><span> </span><span id="local-6989586621679530592"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530592"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-230"></span><span>  </span><span id="local-6989586621679530591"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530591"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CChar -&gt; CString -&gt; IO Int
forall a. (Storable a, Eq a) =&gt; a -&gt; Ptr a -&gt; IO Int
</span><a href="Foreign.Marshal.Array.html#lengthArray0"><span class="hs-identifier hs-var">lengthArray0</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="Foreign.C.String.html#nUL"><span class="hs-identifier hs-var">nUL</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530592"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-231"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530591"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530587"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530591"><span class="hs-identifier hs-var">l</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-232"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-233"></span><span>    </span><span id="local-6989586621679530587"><span class="annot"><span class="annottext">loop :: String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530587"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679530579"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530579"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679530578"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530578"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-234"></span><span>        </span><span id="local-6989586621679530577"><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530577"><span class="hs-identifier hs-var">xval</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; IO CChar
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530592"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530578"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-235"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679530575"><span class="annot"><span class="annottext">val :: Char
</span><a href="#local-6989586621679530575"><span class="hs-identifier hs-var hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CChar -&gt; Char
</span><a href="Foreign.C.String.html#castCCharToChar"><span class="hs-identifier hs-var">castCCharToChar</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530577"><span class="hs-identifier hs-var">xval</span></a></span><span>
</span><span id="line-236"></span><span>        </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530575"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; IO String -&gt; IO String
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530578"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530575"><span class="hs-identifier hs-var">val</span></a></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530579"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530587"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530575"><span class="hs-identifier hs-var">val</span></a></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530579"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530578"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span>
</span><span id="line-238"></span><span class="hs-comment">-- | Marshal a C string with explicit length into a Haskell string.</span><span>
</span><span id="line-239"></span><span class="hs-comment">--</span><span>
</span><span id="line-240"></span><span class="annot"><a href="Foreign.C.String.html#peekCAStringLen"><span class="hs-identifier hs-type">peekCAStringLen</span></a></span><span>           </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-241"></span><span id="peekCAStringLen"><span class="annot"><span class="annottext">peekCAStringLen :: CStringLen -&gt; IO String
</span><a href="Foreign.C.String.html#peekCAStringLen"><span class="hs-identifier hs-var hs-var">peekCAStringLen</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530574"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530574"><span class="hs-identifier hs-var">cp</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679530573"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530573"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-242"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530573"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="hs-comment">-- being (too?) nice.</span><span>
</span><span id="line-243"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530572"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530573"><span class="hs-identifier hs-var">len</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-244"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-245"></span><span>    </span><span id="local-6989586621679530572"><span class="annot"><span class="annottext">loop :: String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530572"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679530563"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530563"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span id="local-6989586621679530562"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530562"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-246"></span><span>         </span><span id="local-6989586621679530561"><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530561"><span class="hs-identifier hs-var">xval</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; IO CChar
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530574"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530562"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-247"></span><span>         </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679530560"><span class="annot"><span class="annottext">val :: Char
</span><a href="#local-6989586621679530560"><span class="hs-identifier hs-var hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CChar -&gt; Char
</span><a href="Foreign.C.String.html#castCCharToChar"><span class="hs-identifier hs-var">castCCharToChar</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="#local-6989586621679530561"><span class="hs-identifier hs-var">xval</span></a></span><span>
</span><span id="line-248"></span><span>           </span><span class="hs-comment">-- blow away the coercion ASAP.</span><span>
</span><span id="line-249"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530560"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530562"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-250"></span><span>          </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530560"><span class="hs-identifier hs-var">val</span></a></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530563"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-251"></span><span>          </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679530572"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530560"><span class="hs-identifier hs-var">val</span></a></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530563"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530562"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-252"></span><span>
</span><span id="line-253"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C string.</span><span>
</span><span id="line-254"></span><span class="hs-comment">--</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-256"></span><span class="hs-comment">--</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- * new storage is allocated for the C string and must be</span><span>
</span><span id="line-258"></span><span class="hs-comment">--   explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-259"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-260"></span><span class="hs-comment">--</span><span>
</span><span id="line-261"></span><span class="annot"><a href="Foreign.C.String.html#newCAString"><span class="hs-identifier hs-type">newCAString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span>
</span><span id="line-262"></span><span id="newCAString"><span class="annot"><span class="annottext">newCAString :: String -&gt; IO CString
</span><a href="Foreign.C.String.html#newCAString"><span class="hs-identifier hs-var hs-var">newCAString</span></a></span></span><span> </span><span id="local-6989586621679530559"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530559"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-263"></span><span>  </span><span id="local-6989586621679530558"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530558"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO CString
forall a. Storable a =&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Array.html#mallocArray0"><span class="hs-identifier hs-var">mallocArray0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530559"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-264"></span><span>  </span><span class="hs-keyword">let</span><span>
</span><span id="line-265"></span><span>        </span><span id="local-6989586621679530550"><span class="annot"><span class="annottext">go :: String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530550"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679530549"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530549"><span class="hs-identifier hs-var">n</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530558"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530549"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="Foreign.C.String.html#nUL"><span class="hs-identifier hs-var">nUL</span></a></span><span>
</span><span id="line-266"></span><span>        </span><span class="annot"><a href="#local-6989586621679530550"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530547"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530547"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530546"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530546"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679530545"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530545"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530558"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530545"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; CChar
</span><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-var">castCharToCChar</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530547"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530550"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530546"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530545"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-267"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530550"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530559"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-268"></span><span>  </span><span class="annot"><span class="annottext">CString -&gt; IO CString
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530558"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span class="hs-comment">-- | Marshal a Haskell string into a C string (ie, character array) with</span><span>
</span><span id="line-271"></span><span class="hs-comment">-- explicit length information.</span><span>
</span><span id="line-272"></span><span class="hs-comment">--</span><span>
</span><span id="line-273"></span><span class="hs-comment">-- * new storage is allocated for the C string and must be</span><span>
</span><span id="line-274"></span><span class="hs-comment">--   explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-275"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-276"></span><span class="hs-comment">--</span><span>
</span><span id="line-277"></span><span class="annot"><a href="Foreign.C.String.html#newCAStringLen"><span class="hs-identifier hs-type">newCAStringLen</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span>
</span><span id="line-278"></span><span id="newCAStringLen"><span class="annot"><span class="annottext">newCAStringLen :: String -&gt; IO CStringLen
</span><a href="Foreign.C.String.html#newCAStringLen"><span class="hs-identifier hs-var hs-var">newCAStringLen</span></a></span></span><span> </span><span id="local-6989586621679530543"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530543"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-279"></span><span>  </span><span id="local-6989586621679530542"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530542"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO CString
forall a. Storable a =&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Array.html#mallocArray0"><span class="hs-identifier hs-var">mallocArray0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530541"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-280"></span><span>  </span><span class="hs-keyword">let</span><span>
</span><span id="line-281"></span><span>        </span><span id="local-6989586621679530535"><span class="annot"><span class="annottext">go :: String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530535"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679530534"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530534"><span class="hs-identifier hs-var">n</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530534"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO () -&gt; IO ()
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- make it strict in n</span><span>
</span><span id="line-282"></span><span>        </span><span class="annot"><a href="#local-6989586621679530535"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530533"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530533"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530532"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530532"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679530531"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530531"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530542"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530531"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; CChar
</span><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-var">castCharToCChar</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530533"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530535"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530532"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530531"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-283"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530535"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530543"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-284"></span><span>  </span><span class="annot"><span class="annottext">CStringLen -&gt; IO CStringLen
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530542"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530541"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-285"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-286"></span><span>    </span><span id="local-6989586621679530541"><span class="annot"><span class="annottext">len :: Int
</span><a href="#local-6989586621679530541"><span class="hs-identifier hs-var hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530543"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-287"></span><span>
</span><span id="line-288"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C string using temporary</span><span>
</span><span id="line-289"></span><span class="hs-comment">-- storage.</span><span>
</span><span id="line-290"></span><span class="hs-comment">--</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-292"></span><span class="hs-comment">--</span><span>
</span><span id="line-293"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-294"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-295"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-296"></span><span class="hs-comment">--</span><span>
</span><span id="line-297"></span><span id="local-6989586621679530530"><span class="annot"><a href="Foreign.C.String.html#withCAString"><span class="hs-identifier hs-type">withCAString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530530"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530530"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-298"></span><span id="withCAString"><span class="annot"><span class="annottext">withCAString :: forall a. String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCAString"><span class="hs-identifier hs-var hs-var">withCAString</span></a></span></span><span> </span><span id="local-6989586621679530527"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530527"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621679530526"><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679530526"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-299"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; (CString -&gt; IO a) -&gt; IO a
forall a b. Storable a =&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#allocaArray0"><span class="hs-identifier hs-var">allocaArray0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530527"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO a) -&gt; IO a) -&gt; (CString -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679530524"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530524"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-300"></span><span>      </span><span class="hs-keyword">let</span><span>
</span><span id="line-301"></span><span>        </span><span id="local-6989586621679530518"><span class="annot"><span class="annottext">go :: String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530518"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679530517"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530517"><span class="hs-identifier hs-var">n</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530524"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530517"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">CChar
</span><a href="Foreign.C.String.html#nUL"><span class="hs-identifier hs-var">nUL</span></a></span><span>
</span><span id="line-302"></span><span>        </span><span class="annot"><a href="#local-6989586621679530518"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530516"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530516"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530515"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530515"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679530514"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530514"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530524"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530514"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; CChar
</span><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-var">castCharToCChar</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530516"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530518"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530515"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530514"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-303"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-304"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530518"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530527"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-305"></span><span>      </span><span class="annot"><span class="annottext">CString -&gt; IO a
</span><a href="#local-6989586621679530526"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530524"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-306"></span><span>
</span><span id="line-307"></span><span class="hs-comment">-- | Marshal a Haskell string into a C string (ie, character array)</span><span>
</span><span id="line-308"></span><span class="hs-comment">-- in temporary storage, with explicit length information.</span><span>
</span><span id="line-309"></span><span class="hs-comment">--</span><span>
</span><span id="line-310"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-311"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-312"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-313"></span><span class="hs-comment">--</span><span>
</span><span id="line-314"></span><span id="local-6989586621679530513"><span class="annot"><a href="Foreign.C.String.html#withCAStringLen"><span class="hs-identifier hs-type">withCAStringLen</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CStringLen"><span class="hs-identifier hs-type">CStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530513"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530513"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-315"></span><span id="withCAStringLen"><span class="annot"><span class="annottext">withCAStringLen :: forall a. String -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCAStringLen"><span class="hs-identifier hs-var hs-var">withCAStringLen</span></a></span></span><span> </span><span id="local-6989586621679530510"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530510"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621679530509"><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679530509"><span class="hs-identifier hs-var">f</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span>
</span><span id="line-316"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; (CString -&gt; IO a) -&gt; IO a
forall a b. Storable a =&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#allocaArray"><span class="hs-identifier hs-var">allocaArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530507"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO a) -&gt; IO a) -&gt; (CString -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679530506"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530506"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-317"></span><span>      </span><span class="hs-keyword">let</span><span>
</span><span id="line-318"></span><span>        </span><span id="local-6989586621679530500"><span class="annot"><span class="annottext">go :: String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530500"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679530499"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530499"><span class="hs-identifier hs-var">n</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530499"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO () -&gt; IO ()
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- make it strict in n</span><span>
</span><span id="line-319"></span><span>        </span><span class="annot"><a href="#local-6989586621679530500"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530498"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530498"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530497"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530497"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679530496"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530496"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CString -&gt; Int -&gt; CChar -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530506"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530496"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; CChar
</span><a href="Foreign.C.String.html#castCharToCChar"><span class="hs-identifier hs-var">castCharToCChar</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679530498"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530500"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530497"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530496"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-320"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-321"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679530500"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530510"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-322"></span><span>      </span><span class="annot"><span class="annottext">CStringLen -&gt; IO a
</span><a href="#local-6989586621679530509"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679530506"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530507"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-323"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-324"></span><span>    </span><span id="local-6989586621679530507"><span class="annot"><span class="annottext">len :: Int
</span><a href="#local-6989586621679530507"><span class="hs-identifier hs-var hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530510"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-325"></span><span>
</span><span id="line-326"></span><span class="hs-comment">-- auxiliary definitions</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- ----------------------</span><span>
</span><span id="line-328"></span><span>
</span><span id="line-329"></span><span class="hs-comment">-- C's end of string character</span><span>
</span><span id="line-330"></span><span class="hs-comment">--</span><span>
</span><span id="line-331"></span><span class="annot"><a href="Foreign.C.String.html#nUL"><span class="hs-identifier hs-type">nUL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span>
</span><span id="line-332"></span><span id="nUL"><span class="annot"><span class="annottext">nUL :: CChar
</span><a href="Foreign.C.String.html#nUL"><span class="hs-identifier hs-var hs-var">nUL</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CChar
</span><span class="hs-number">0</span></span><span>
</span><span id="line-333"></span><span>
</span><span id="line-334"></span><span class="hs-comment">-- allocate an array to hold the list and pair it with the number of elements</span><span>
</span><span id="line-335"></span><span id="local-6989586621679530754"><span class="annot"><a href="Foreign.C.String.html#newArrayLen"><span class="hs-identifier hs-type">newArrayLen</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530754"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679530754"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530754"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-336"></span><span id="newArrayLen"><span class="annot"><span class="annottext">newArrayLen :: forall a. Storable a =&gt; [a] -&gt; IO (Ptr a, Int)
</span><a href="Foreign.C.String.html#newArrayLen"><span class="hs-identifier hs-var hs-var">newArrayLen</span></a></span></span><span> </span><span id="local-6989586621679530490"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530490"><span class="hs-identifier hs-var">xs</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-337"></span><span>  </span><span id="local-6989586621679530489"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679530489"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; IO (Ptr a)
forall a. Storable a =&gt; [a] -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Array.html#newArray"><span class="hs-identifier hs-var">newArray</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530490"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-338"></span><span>  </span><span class="annot"><span class="annottext">(Ptr a, Int) -&gt; IO (Ptr a, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679530489"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530490"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-339"></span><span>
</span><span id="line-340"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-341"></span><span class="hs-comment">-- Wide strings</span><span>
</span><span id="line-342"></span><span>
</span><span id="line-343"></span><span class="hs-comment">-- representation of wide strings in C</span><span>
</span><span id="line-344"></span><span class="hs-comment">-- -----------------------------------</span><span>
</span><span id="line-345"></span><span>
</span><span id="line-346"></span><span class="hs-comment">-- | A C wide string is a reference to an array of C wide characters</span><span>
</span><span id="line-347"></span><span class="hs-comment">-- terminated by NUL.</span><span>
</span><span id="line-348"></span><span class="hs-keyword">type</span><span> </span><span id="CWString"><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-var">CWString</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span>
</span><span id="line-349"></span><span>
</span><span id="line-350"></span><span class="hs-comment">-- | A wide character string with explicit length information in 'CWchar's</span><span>
</span><span id="line-351"></span><span class="hs-comment">-- instead of a terminating NUL (allowing NUL characters in the middle</span><span>
</span><span id="line-352"></span><span class="hs-comment">-- of the string).</span><span>
</span><span id="line-353"></span><span class="hs-keyword">type</span><span> </span><span id="CWStringLen"><span class="annot"><a href="Foreign.C.String.html#CWStringLen"><span class="hs-identifier hs-var">CWStringLen</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-354"></span><span>
</span><span id="line-355"></span><span class="hs-comment">-- | Marshal a NUL terminated C wide string into a Haskell string.</span><span>
</span><span id="line-356"></span><span class="hs-comment">--</span><span>
</span><span id="line-357"></span><span class="annot"><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-type">peekCWString</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-358"></span><span id="peekCWString"><span class="annot"><span class="annottext">peekCWString :: CWString -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-var hs-var">peekCWString</span></a></span></span><span> </span><span id="local-6989586621679530487"><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530487"><span class="hs-identifier hs-var">cp</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-359"></span><span>  </span><span id="local-6989586621679530486"><span class="annot"><span class="annottext">[CWchar]
</span><a href="#local-6989586621679530486"><span class="hs-identifier hs-var">cs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; CWString -&gt; IO [CWchar]
forall a. (Storable a, Eq a) =&gt; a -&gt; Ptr a -&gt; IO [a]
</span><a href="Foreign.Marshal.Array.html#peekArray0"><span class="hs-identifier hs-var">peekArray0</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar
</span><a href="Foreign.C.String.html#wNUL"><span class="hs-identifier hs-var">wNUL</span></a></span><span> </span><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530487"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-360"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CWchar] -&gt; String
</span><a href="Foreign.C.String.html#cWcharsToChars"><span class="hs-identifier hs-var">cWcharsToChars</span></a></span><span> </span><span class="annot"><span class="annottext">[CWchar]
</span><a href="#local-6989586621679530486"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-361"></span><span>
</span><span id="line-362"></span><span class="hs-comment">-- | Marshal a C wide string with explicit length into a Haskell string.</span><span>
</span><span id="line-363"></span><span class="hs-comment">--</span><span>
</span><span id="line-364"></span><span class="annot"><a href="Foreign.C.String.html#peekCWStringLen"><span class="hs-identifier hs-type">peekCWStringLen</span></a></span><span>           </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWStringLen"><span class="hs-identifier hs-type">CWStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-365"></span><span id="peekCWStringLen"><span class="annot"><span class="annottext">peekCWStringLen :: CWStringLen -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWStringLen"><span class="hs-identifier hs-var hs-var">peekCWStringLen</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530482"><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530482"><span class="hs-identifier hs-var">cp</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679530481"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530481"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-366"></span><span>  </span><span id="local-6989586621679530480"><span class="annot"><span class="annottext">[CWchar]
</span><a href="#local-6989586621679530480"><span class="hs-identifier hs-var">cs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CWString -&gt; IO [CWchar]
forall a. Storable a =&gt; Int -&gt; Ptr a -&gt; IO [a]
</span><a href="Foreign.Marshal.Array.html#peekArray"><span class="hs-identifier hs-var">peekArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530481"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530482"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-367"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CWchar] -&gt; String
</span><a href="Foreign.C.String.html#cWcharsToChars"><span class="hs-identifier hs-var">cWcharsToChars</span></a></span><span> </span><span class="annot"><span class="annottext">[CWchar]
</span><a href="#local-6989586621679530480"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-368"></span><span>
</span><span id="line-369"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C wide string.</span><span>
</span><span id="line-370"></span><span class="hs-comment">--</span><span>
</span><span id="line-371"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-372"></span><span class="hs-comment">--</span><span>
</span><span id="line-373"></span><span class="hs-comment">-- * new storage is allocated for the C wide string and must</span><span>
</span><span id="line-374"></span><span class="hs-comment">--   be explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-375"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-376"></span><span class="hs-comment">--</span><span>
</span><span id="line-377"></span><span class="annot"><a href="Foreign.C.String.html#newCWString"><span class="hs-identifier hs-type">newCWString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span>
</span><span id="line-378"></span><span id="newCWString"><span class="annot"><span class="annottext">newCWString :: String -&gt; IO CWString
</span><a href="Foreign.C.String.html#newCWString"><span class="hs-identifier hs-var hs-var">newCWString</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; [CWchar] -&gt; IO CWString
forall a. Storable a =&gt; a -&gt; [a] -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Array.html#newArray0"><span class="hs-identifier hs-var">newArray0</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar
</span><a href="Foreign.C.String.html#wNUL"><span class="hs-identifier hs-var">wNUL</span></a></span><span> </span><span class="annot"><span class="annottext">([CWchar] -&gt; IO CWString)
-&gt; (String -&gt; [CWchar]) -&gt; String -&gt; IO CWString
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; [CWchar]
</span><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-var">charsToCWchars</span></a></span><span>
</span><span id="line-379"></span><span>
</span><span id="line-380"></span><span class="hs-comment">-- | Marshal a Haskell string into a C wide string (ie, wide character array)</span><span>
</span><span id="line-381"></span><span class="hs-comment">-- with explicit length information.</span><span>
</span><span id="line-382"></span><span class="hs-comment">--</span><span>
</span><span id="line-383"></span><span class="hs-comment">-- * new storage is allocated for the C wide string and must</span><span>
</span><span id="line-384"></span><span class="hs-comment">--   be explicitly freed using 'Foreign.Marshal.Alloc.free' or</span><span>
</span><span id="line-385"></span><span class="hs-comment">--   'Foreign.Marshal.Alloc.finalizerFree'.</span><span>
</span><span id="line-386"></span><span class="hs-comment">--</span><span>
</span><span id="line-387"></span><span class="annot"><a href="Foreign.C.String.html#newCWStringLen"><span class="hs-identifier hs-type">newCWStringLen</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWStringLen"><span class="hs-identifier hs-type">CWStringLen</span></a></span><span>
</span><span id="line-388"></span><span id="newCWStringLen"><span class="annot"><span class="annottext">newCWStringLen :: String -&gt; IO CWStringLen
</span><a href="Foreign.C.String.html#newCWStringLen"><span class="hs-identifier hs-var hs-var">newCWStringLen</span></a></span></span><span> </span><span id="local-6989586621679530475"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530475"><span class="hs-identifier hs-var">str</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CWchar] -&gt; IO CWStringLen
forall a. Storable a =&gt; [a] -&gt; IO (Ptr a, Int)
</span><a href="Foreign.C.String.html#newArrayLen"><span class="hs-identifier hs-var">newArrayLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; [CWchar]
</span><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-var">charsToCWchars</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530475"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-389"></span><span>
</span><span id="line-390"></span><span class="hs-comment">-- | Marshal a Haskell string into a NUL terminated C wide string using</span><span>
</span><span id="line-391"></span><span class="hs-comment">-- temporary storage.</span><span>
</span><span id="line-392"></span><span class="hs-comment">--</span><span>
</span><span id="line-393"></span><span class="hs-comment">-- * the Haskell string may /not/ contain any NUL characters</span><span>
</span><span id="line-394"></span><span class="hs-comment">--</span><span>
</span><span id="line-395"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-396"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-397"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-398"></span><span class="hs-comment">--</span><span>
</span><span id="line-399"></span><span id="local-6989586621679530743"><span class="annot"><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-type">withCWString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530743"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530743"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-400"></span><span id="withCWString"><span class="annot"><span class="annottext">withCWString :: forall a. String -&gt; (CWString -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var hs-var">withCWString</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; [CWchar] -&gt; (CWString -&gt; IO a) -&gt; IO a
forall a b. Storable a =&gt; a -&gt; [a] -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#withArray0"><span class="hs-identifier hs-var">withArray0</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar
</span><a href="Foreign.C.String.html#wNUL"><span class="hs-identifier hs-var">wNUL</span></a></span><span> </span><span class="annot"><span class="annottext">([CWchar] -&gt; (CWString -&gt; IO a) -&gt; IO a)
-&gt; (String -&gt; [CWchar]) -&gt; String -&gt; (CWString -&gt; IO a) -&gt; IO a
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; [CWchar]
</span><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-var">charsToCWchars</span></a></span><span>
</span><span id="line-401"></span><span>
</span><span id="line-402"></span><span class="hs-comment">-- | Marshal a Haskell string into a C wide string (i.e. wide</span><span>
</span><span id="line-403"></span><span class="hs-comment">-- character array) in temporary storage, with explicit length</span><span>
</span><span id="line-404"></span><span class="hs-comment">-- information.</span><span>
</span><span id="line-405"></span><span class="hs-comment">--</span><span>
</span><span id="line-406"></span><span class="hs-comment">-- * the memory is freed when the subcomputation terminates (either</span><span>
</span><span id="line-407"></span><span class="hs-comment">--   normally or via an exception), so the pointer to the temporary</span><span>
</span><span id="line-408"></span><span class="hs-comment">--   storage must /not/ be used after this.</span><span>
</span><span id="line-409"></span><span class="hs-comment">--</span><span>
</span><span id="line-410"></span><span id="local-6989586621679530739"><span class="annot"><a href="Foreign.C.String.html#withCWStringLen"><span class="hs-identifier hs-type">withCWStringLen</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.C.String.html#CWStringLen"><span class="hs-identifier hs-type">CWStringLen</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530739"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679530739"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-411"></span><span id="withCWStringLen"><span class="annot"><span class="annottext">withCWStringLen :: forall a. String -&gt; (CWStringLen -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWStringLen"><span class="hs-identifier hs-var hs-var">withCWStringLen</span></a></span></span><span> </span><span id="local-6989586621679530471"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530471"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621679530470"><span class="annot"><span class="annottext">CWStringLen -&gt; IO a
</span><a href="#local-6989586621679530470"><span class="hs-identifier hs-var">f</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span>
</span><span id="line-412"></span><span>  </span><span class="annot"><span class="annottext">[CWchar] -&gt; (Int -&gt; CWString -&gt; IO a) -&gt; IO a
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#withArrayLen"><span class="hs-identifier hs-var">withArrayLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; [CWchar]
</span><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-var">charsToCWchars</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679530471"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Int -&gt; CWString -&gt; IO a) -&gt; IO a)
-&gt; (Int -&gt; CWString -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679530468"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530468"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679530467"><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530467"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CWStringLen -&gt; IO a
</span><a href="#local-6989586621679530470"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CWString
</span><a href="#local-6989586621679530467"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679530468"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-413"></span><span>
</span><span id="line-414"></span><span class="hs-comment">-- auxiliary definitions</span><span>
</span><span id="line-415"></span><span class="hs-comment">-- ----------------------</span><span>
</span><span id="line-416"></span><span>
</span><span id="line-417"></span><span class="annot"><a href="Foreign.C.String.html#wNUL"><span class="hs-identifier hs-type">wNUL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span>
</span><span id="line-418"></span><span id="wNUL"><span class="annot"><span class="annottext">wNUL :: CWchar
</span><a href="Foreign.C.String.html#wNUL"><span class="hs-identifier hs-var hs-var">wNUL</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CWchar
</span><span class="hs-number">0</span></span><span>
</span><span id="line-419"></span><span>
</span><span id="line-420"></span><span class="annot"><a href="Foreign.C.String.html#cWcharsToChars"><span class="hs-identifier hs-type">cWcharsToChars</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-421"></span><span class="annot"><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-type">charsToCWchars</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">]</span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span>
</span><span id="line-425"></span><span class="hs-comment">-- On Windows, wchar_t is 16 bits wide and CWString uses the UTF-16 encoding.</span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span class="hs-comment">-- coding errors generate Chars in the surrogate range</span><span>
</span><span id="line-428"></span><span id="cWcharsToChars"><span class="annot"><span class="annottext">cWcharsToChars :: [CWchar] -&gt; String
</span><a href="Foreign.C.String.html#cWcharsToChars"><span class="hs-identifier hs-var hs-var">cWcharsToChars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; Char) -&gt; [Int] -&gt; String
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Char
</span><a href="GHC.Char.html#chr"><span class="hs-identifier hs-var">chr</span></a></span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; String) -&gt; ([CWchar] -&gt; [Int]) -&gt; [CWchar] -&gt; String
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; [Int]
forall {a}. (Ord a, Num a) =&gt; [a] -&gt; [a]
</span><a href="#local-6989586621679530465"><span class="hs-identifier hs-var">fromUTF16</span></a></span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; [Int]) -&gt; ([CWchar] -&gt; [Int]) -&gt; [CWchar] -&gt; [Int]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(CWchar -&gt; Int) -&gt; [CWchar] -&gt; [Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span>
</span><span id="line-429"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-430"></span><span>  </span><span id="local-6989586621679530465"><span class="annot"><span class="annottext">fromUTF16 :: [a] -&gt; [a]
</span><a href="#local-6989586621679530465"><span class="hs-identifier hs-var hs-var">fromUTF16</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530445"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530445"><span class="hs-identifier hs-var">c1</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530444"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530444"><span class="hs-identifier hs-var">c2</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530443"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530443"><span class="hs-identifier hs-var">wcs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-431"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xd800</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530445"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530445"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xdbff</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xdc00</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530444"><span class="hs-identifier hs-var">c2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530444"><span class="hs-identifier hs-var">c2</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xdfff</span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-432"></span><span>      </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530445"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xd800</span></span><span class="hs-special">)</span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x400</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530444"><span class="hs-identifier hs-var">c2</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xdc00</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x10000</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
</span><a href="#local-6989586621679530465"><span class="hs-identifier hs-var">fromUTF16</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530443"><span class="hs-identifier hs-var">wcs</span></a></span><span>
</span><span id="line-433"></span><span>  </span><span class="annot"><a href="#local-6989586621679530465"><span class="hs-identifier hs-var">fromUTF16</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679530440"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530440"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679530439"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530439"><span class="hs-identifier hs-var">wcs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530440"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
</span><a href="#local-6989586621679530465"><span class="hs-identifier hs-var">fromUTF16</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530439"><span class="hs-identifier hs-var">wcs</span></a></span><span>
</span><span id="line-434"></span><span>  </span><span class="annot"><a href="#local-6989586621679530465"><span class="hs-identifier hs-var">fromUTF16</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-435"></span><span>
</span><span id="line-436"></span><span id="charsToCWchars"><span class="annot"><span class="annottext">charsToCWchars :: String -&gt; [CWchar]
</span><a href="Foreign.C.String.html#charsToCWchars"><span class="hs-identifier hs-var hs-var">charsToCWchars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; [CWchar] -&gt; [CWchar]) -&gt; [CWchar] -&gt; [Int] -&gt; [CWchar]
forall a b. (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
</span><a href="GHC.Base.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; [CWchar] -&gt; [CWchar]
forall {a} {a}. (Integral a, Num a) =&gt; a -&gt; [a] -&gt; [a]
</span><a href="#local-6989586621679530438"><span class="hs-identifier hs-var">utf16Char</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; [CWchar]) -&gt; (String -&gt; [Int]) -&gt; String -&gt; [CWchar]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Int) -&gt; String -&gt; [Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Int
</span><a href="GHC.Base.html#ord"><span class="hs-identifier hs-var">ord</span></a></span><span>
</span><span id="line-437"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-438"></span><span>  </span><span id="local-6989586621679530438"><span class="annot"><span class="annottext">utf16Char :: a -&gt; [a] -&gt; [a]
</span><a href="#local-6989586621679530438"><span class="hs-identifier hs-var hs-var">utf16Char</span></a></span></span><span> </span><span id="local-6989586621679530413"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530413"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679530412"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530412"><span class="hs-identifier hs-var">wcs</span></a></span></span><span>
</span><span id="line-439"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530413"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x10000</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530413"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530412"><span class="hs-identifier hs-var">wcs</span></a></span><span>
</span><span id="line-440"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679530408"><span class="annot"><span class="annottext">c' :: a
</span><a href="#local-6989586621679530408"><span class="hs-identifier hs-var hs-var">c'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530413"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x10000</span></span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-441"></span><span>                    </span><span class="annot"><span class="annottext">a -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530408"><span class="hs-identifier hs-var">c'</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x400</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xd800</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span>
</span><span id="line-442"></span><span>                    </span><span class="annot"><span class="annottext">a -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679530408"><span class="hs-identifier hs-var">c'</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#mod"><span class="hs-operator hs-var">`mod`</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0x400</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0xdc00</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679530412"><span class="hs-identifier hs-var">wcs</span></a></span><span class="hs-cpp">

#else /* !mingw32_HOST_OS */
</span><span>
</span><span id="line-446"></span><span class="hs-identifier">cWcharsToChars</span><span> </span><span class="hs-identifier">xs</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">map</span><span> </span><span class="hs-identifier">castCWcharToChar</span><span> </span><span class="hs-identifier">xs</span><span>
</span><span id="line-447"></span><span class="hs-identifier">charsToCWchars</span><span> </span><span class="hs-identifier">xs</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">map</span><span> </span><span class="hs-identifier">castCharToCWchar</span><span> </span><span class="hs-identifier">xs</span><span>
</span><span id="line-448"></span><span>
</span><span id="line-449"></span><span class="hs-comment">-- These conversions only make sense if __STDC_ISO_10646__ is defined</span><span>
</span><span id="line-450"></span><span class="hs-comment">-- (meaning that wchar_t is ISO 10646, aka Unicode)</span><span>
</span><span id="line-451"></span><span>
</span><span id="line-452"></span><span class="hs-identifier">castCWcharToChar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CWchar</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Char</span><span>
</span><span id="line-453"></span><span class="hs-identifier">castCWcharToChar</span><span> </span><span class="hs-identifier">ch</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">chr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">ch</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-454"></span><span>
</span><span id="line-455"></span><span class="hs-identifier">castCharToCWchar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Char</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CWchar</span><span>
</span><span id="line-456"></span><span class="hs-identifier">castCharToCWchar</span><span> </span><span class="hs-identifier">ch</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">ch</span><span class="hs-special">)</span><span class="hs-cpp">

#endif /* !mingw32_HOST_OS */
</span><span>
</span><span id="line-460"></span></pre></body></html>